import React, { useState, useEffect } from "react";
import { NavBar } from "antd-mobile";
import "./index.less";
import { reqBannerList,reqGrouponList ,reqGoodsList} from "../../http/api";
import { initState, reducer, actions } from "../Login/user";

//组件
import Sea from "../../components/Sea";
import New from "./compones/New/New";
import Nav from "../Index/compones/Nav/Nav.jsx";
import Banner from "./compones/Banner/Banner";
import Goods from "./compones/Goods/Goods";
//静态资源
import Xiao from "../../assets/img/pic_logo_white 2.png";
import Site from "../../assets/img/icon_location@3x.png";

export default function Index(props) {
  const [banner, setBanner] = useState([]);
  const [wan, setWan] = useState([]);
  const [goods, setGoods] = useState([]);
  const [n, setN] = useState(0);
  useEffect(() => {
    reqBannerList().then((res) => {
      if (res.data.code === 200) {
        setBanner(res.data.list);
      }
    });
    reqGrouponList().then((res) => {
      if (res.data.code === 200) {
        setWan(res.data.list);
      }
    });
    reqGoodsList().then((res) => {
      if (res.data.code === 200) {
        setGoods(res.data.list);
      }
    });
  }, []);
  return (
    <div className="index">
      <NavBar
        mode="light"
        icon={<img src={Xiao}></img>}
        rightContent={[<img src={Site} key={0}></img>]}
      >
        <Sea {...props}></Sea>
      </NavBar>
      {/* 一重礼 */}
      <New
        {...props}
        banner={banner}
        but={"一重礼"}
        sp1={"新人特价商品"}
        sp2={"(限量供应,先到先得)"}
      ></New>
      {/* 秒杀活动 */}
      <Nav list={banner[0] ? banner[0] : []} {...props}></Nav>
      {/* 二重礼 */}
      {wan.length > 0 ? <Banner{...props}
        banner={wan}
        type={2}
        but={"限时秒杀"}
        sp1={"信任商品特区"}
        sp2={"(限量供应,先到先得)"}></Banner> : null}
      <Goods goods={goods} n={n} setN={(e) => setN(e)} {...props}></Goods>
    </div>
  );
}
